Skip to content

Add SRI integrity hashes to CDN resources in docs HTML files (2.x)#593

Open
Copilot wants to merge 4 commits into2.xfrom
copilot/add-checksum-to-html-tags-2-x
Open

Add SRI integrity hashes to CDN resources in docs HTML files (2.x)#593
Copilot wants to merge 4 commits into2.xfrom
copilot/add-checksum-to-html-tags-2-x

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Summary

Adds Subresource Integrity (SRI) integrity and crossorigin="anonymous" attributes to all HTML tags that load external CDN resources in the documentation site files, to prevent supply-chain attacks.

This mirrors the same security measures already applied on the gh-pages branch (see copilot/fix-docs-html-attributes), now applied to the 2.x branch.

Changes

  • Added SRI integrity hashes and crossorigin="anonymous" to all CDN resource tags in 10 HTML files under docs/source/site/:

    • //cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.cssintegrity="sha384-WtUWHyk39lfUpZQVgokNfSKCJaKAeD6adgLduBLrKTMUuPzFhLtL23y1guFy6lZn"
    • //cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.jsintegrity="sha384-ZeLYJ2PNSQjvogWP559CDAf02Qb8FE5OyQicqtz/+UhZutbrwyr87Be7NPH/RgyC"
  • Added docs/source/custom_theme/base.html — a MkDocs theme override (based on the MkDocs 1.0.4 readthedocs base.html) with the SRI integrity and crossorigin attributes included on both CDN tags, so future mkdocs build runs preserve the security hardening automatically. The template also uses a fail-secure pattern for the hljs_languages for loop: additional language files are only loaded when their pre-verified SRI hash is present in a hljs_lang_sri dictionary defined in the template. Languages without a known hash are skipped rather than loaded without integrity verification. Any future hljs_languages entry in mkdocs.yml must have a corresponding hash added to the template dictionary before it will be served.

  • Updated docs/source/mkdocs.yml to use custom_dir: custom_theme, enabling the template override on every rebuild.

Note: The Google Fonts <link> tags are intentionally left unchanged, as Google Fonts serves dynamically-generated CSS (varying by browser user-agent) which cannot have a stable, pre-computed SRI hash.

SRI Hash Verification

The SRI hashes were computed from the exact bytes stored in the cdnjs GitHub repository, verified against the git blob SHA values:

  • github.min.css blob SHA: 5477a1b9d6ab51515f7fa40df696ce06137350f5
  • highlight.min.js blob SHA: f30a334c9d15d3d6e85a5c6b06f4ab915dfea344

Copilot AI requested a review from revagomes April 17, 2026 23:28
@revagomes revagomes marked this pull request as ready for review April 17, 2026 23:28
Copilot AI review requested due to automatic review settings April 17, 2026 23:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Subresource Integrity (SRI) attributes to externally loaded Highlight.js assets in the MkDocs-generated documentation HTML, to reduce CDN supply-chain risk on the 2.x branch.

Changes:

  • Added integrity and crossorigin="anonymous" to the Highlight.js CDN stylesheet <link>.
  • Added integrity and crossorigin="anonymous" to the Highlight.js CDN script <script>.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/source/site/usersguide/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/search.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/legal/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/installation/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/gettingstarted/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/datamanagement/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/contributors/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/about/index.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.
docs/source/site/404.html Adds SRI + crossorigin to Highlight.js CDN CSS/JS includes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/source/site/index.html
Copilot AI requested a review from revagomes April 17, 2026 23:39
Comment thread docs/source/custom_theme/base.html Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/languages/{{lang}}.min.js" integrity="{{ hljs_lang_sri[lang] }}" crossorigin="anonymous"></script>
{%- endif %}
{%- endfor %}
<script>hljs.initHighlightingOnLoad();</script>
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hljs.initHighlightingOnLoad() is called unconditionally right after loading highlight.js. If the CDN script fails to load (e.g., SRI mismatch, network block), this will throw a ReferenceError (hljs is undefined) and clutter the console. Consider guarding the call (e.g., check window.hljs before invoking) so the page degrades cleanly when highlighting is unavailable.

Suggested change
<script>hljs.initHighlightingOnLoad();</script>
<script>
if (window.hljs && typeof window.hljs.initHighlightingOnLoad === 'function') {
window.hljs.initHighlightingOnLoad();
}
</script>

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants